package org.hot100_0.leetocde49;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String,List<String>> hashMap = new HashMap<>();

        for (String str : strs) {
            char[] temp = str.toCharArray();
            Arrays.sort(temp);
            String sameStr = new String(temp);
            if (hashMap.containsKey(sameStr)){
                hashMap.get(sameStr).add(str);
            }else {
                ArrayList<String > list = new ArrayList<>();
                list.add(str);
                hashMap.put(sameStr,list);
            }
        }


        return new ArrayList<>(hashMap.values());
    }
}
